clearvars -except Globaloption option

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% This code reads in the VAR dynamics and produce the Campbell-Shiller decomposition in the paper
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Load data
breakpoint = 0;
n_coint_var = 3;
startdatenum = 1817;
enddatenum = 1914;
loaddata;
ttime = [startdate:enddate];

output_rp = 0.03;
filename = ['MAT/Netherland_nostock_', num2str(round(output_rp * 10000)), '_', num2str(startdatenum), '_', num2str(enddatenum)];

%% Estimation
run ../../tools/cs_estimation.m

%% steady-state upper bound calculation
upper = exp(pxbar)*(mean(tau-g));

gdpreturn = output_rp+y0nom_10-pi0;


filename1=['MAT/Netherland_nostock_para_',num2str(round(output_rp*10000)),'_',num2str(startdatenum),'_',num2str(enddatenum)];
save (filename1, 'k0x', 'k1x', 's', 'upper', 'pdX', 'pxbar', 'gdpreturn', 'debt', 'pdG', 'pdT', 'Xraw','Psi')

%% bootstrap
run ../../tools/BS_compute.m

save (filename, 's', 'std_coeff', 'debt', 'upper','debt_adjusted');

